package com.bigflexlib.x.mx.controls.sliderClasses.Slider
{
	
	public class ScaleLinearizerHelper
	{
		
	
		private var minScale:Number;
		private var maxScale:Number;
		
		
		private var minNum:Number;
		private var maxNum:Number;
		
		private var diff:Number;
		

		public function ScaleLinearizerHelper( minScale:Number, maxScale:Number )
		{
			
			this.minScale = minScale;
			this.maxScale = maxScale;

			this.minNum = scale2signedNum( minScale );
			this.maxNum = scale2signedNum( maxScale );
			this.diff = maxNum - minNum;
		}
		
		
		
		internal static function scale2signedNum( scale:Number ):Number
		{
			if ( scale < 1 )
				scale = ( -1/scale ) + 1;
			else
				scale--;
			return scale;
		}
		
		
		internal static function signedNum2scale( signedNum:Number ):Number
		{
			
			if ( signedNum == 0 )
				signedNum = 1;
			else if ( signedNum<0 )
				signedNum -= 1;
			else if ( signedNum>0 )
				signedNum += 1;
				
			return signedNum > 0 ? signedNum : 1/signedNum * -1;			
		
		}
		
		
		
		/**
		 * 
		 * @param point
		 * @return 
		 * 
		 */		
		public function scaleForPoint( point:Number ):Number
		{
			var num:Number = minNum + ( diff * point );
			return signedNum2scale( num );
		}
		
		

		public function pointForScale( scale:Number ):Number
		{
			var num:Number = scale2signedNum( scale );
			num -= minNum;
			return num / diff;

		}
		

	}

}